/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.openams.server.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author mike
 */
@Entity
@Table(name = "datasetinstances")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "DatasetInstance.findAll", query = "SELECT d FROM DatasetInstance d"),
    @NamedQuery(name = "DatasetInstance.findByDatasetInstanceID", query = "SELECT d FROM DatasetInstance d WHERE d.datasetInstanceID = :datasetInstanceID"),
    @NamedQuery(name = "DatasetInstance.findByDateCreated", query = "SELECT d FROM DatasetInstance d WHERE d.dateCreated = :dateCreated"),
    @NamedQuery(name = "DatasetInstance.findByOrdinal", query = "SELECT d FROM DatasetInstance d WHERE d.ordinal = :ordinal")})
public class DatasetInstance implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "DatasetInstanceID", nullable = false)
    private Integer datasetInstanceID;
    @Column(name = "DateCreated")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateCreated;
    @Column(name = "Ordinal")
    private Integer ordinal;
    @OneToMany(mappedBy = "metaDatasetInstanceID", fetch = FetchType.LAZY)
    private Collection<DatasetInstanceAssignment> datasetInstanceAssignmentCollection;
    @OneToMany(mappedBy = "datasetInstanceID", fetch = FetchType.LAZY)
    private Collection<DatasetInstanceAssignment> datasetInstanceAssignmentCollection1;
    @JoinColumn(name = "DatasetTemplateID", referencedColumnName = "DatasetTemplateID", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private DatasetTemplate datasetTemplateID;
    @JoinColumn(name = "ParentDatasetTemplateHierarchyID", referencedColumnName = "DatasetTemplateHierarchyID")
    @ManyToOne(fetch = FetchType.LAZY)
    private DatasetTemplateHierarchy parentDatasetTemplateHierarchyID;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "childDatasetInstanceID", fetch = FetchType.LAZY)
    private Collection<DatasetInstanceHierarchy> datasetInstanceHierarchyCollection;

    public DatasetInstance() {
    }

    public DatasetInstance(Integer datasetInstanceID) {
        this.datasetInstanceID = datasetInstanceID;
    }

    public Integer getDatasetInstanceID() {
        return datasetInstanceID;
    }

    public void setDatasetInstanceID(Integer datasetInstanceID) {
        this.datasetInstanceID = datasetInstanceID;
    }

    public Date getDateCreated() {
        return dateCreated;
    }

    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }

    public Integer getOrdinal() {
        return ordinal;
    }

    public void setOrdinal(Integer ordinal) {
        this.ordinal = ordinal;
    }

    @XmlTransient
    public Collection<DatasetInstanceAssignment> getDatasetInstanceAssignmentCollection() {
        return datasetInstanceAssignmentCollection;
    }

    public void setDatasetInstanceAssignmentCollection(Collection<DatasetInstanceAssignment> datasetInstanceAssignmentCollection) {
        this.datasetInstanceAssignmentCollection = datasetInstanceAssignmentCollection;
    }

    @XmlTransient
    public Collection<DatasetInstanceAssignment> getDatasetInstanceAssignmentCollection1() {
        return datasetInstanceAssignmentCollection1;
    }

    public void setDatasetInstanceAssignmentCollection1(Collection<DatasetInstanceAssignment> datasetInstanceAssignmentCollection1) {
        this.datasetInstanceAssignmentCollection1 = datasetInstanceAssignmentCollection1;
    }

    public DatasetTemplate getDatasetTemplateID() {
        return datasetTemplateID;
    }

    public void setDatasetTemplateID(DatasetTemplate datasetTemplateID) {
        this.datasetTemplateID = datasetTemplateID;
    }

    public DatasetTemplateHierarchy getParentDatasetTemplateHierarchyID() {
        return parentDatasetTemplateHierarchyID;
    }

    public void setParentDatasetTemplateHierarchyID(DatasetTemplateHierarchy parentDatasetTemplateHierarchyID) {
        this.parentDatasetTemplateHierarchyID = parentDatasetTemplateHierarchyID;
    }

    @XmlTransient
    public Collection<DatasetInstanceHierarchy> getDatasetInstanceHierarchyCollection() {
        return datasetInstanceHierarchyCollection;
    }

    public void setDatasetInstanceHierarchyCollection(Collection<DatasetInstanceHierarchy> datasetInstanceHierarchyCollection) {
        this.datasetInstanceHierarchyCollection = datasetInstanceHierarchyCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (datasetInstanceID != null ? datasetInstanceID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof DatasetInstance)) {
            return false;
        }
        DatasetInstance other = (DatasetInstance) object;
        if ((this.datasetInstanceID == null && other.datasetInstanceID != null) || (this.datasetInstanceID != null && !this.datasetInstanceID.equals(other.datasetInstanceID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.openams.server.entity.DatasetInstance[ datasetInstanceID=" + datasetInstanceID + " ]";
    }
    
}
